package com.fengplus.demo.controller;

import com.fengplus.demo.entity.CommonResult;
import com.fengplus.demo.entity.ExceptionResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/e")
public class ExceptionController {

    // 直接排除异常
    @GetMapping("/a")
    public CommonResult a() {
        throw new RuntimeException("异常A");
    }

    // 全局捕抓计算异常
    @GetMapping("/b")
    public CommonResult b() {
        int i = 8 / 0;
        return new CommonResult(200, null, i);
    }

    // 自定义异常
    @GetMapping("/c")
    public CommonResult c() {
        throw new ExceptionResult(400, "自定义异常");
    }

}
